//
//  SampuxCustomNavController.m
//  Sampux
//
//  Created by rzm on 16/7/6.
//  Copyright © 2016年 rzm. All rights reserved.
//

#import "SampuxCustomNavController.h"

@interface SampuxCustomNavController ()

@property (nonatomic, strong) UILabel *titleLab ;

@end

@implementation SampuxCustomNavController

//+ (void)initialize
//{
//    UINavigationBar *navBar = [UINavigationBar appearance];
//    NSMutableDictionary *textAttrs1 = [NSMutableDictionary dictionary];
//    textAttrs1[NSForegroundColorAttributeName] = [UIColor whiteColor];
//    textAttrs1[NSFontAttributeName] = [UIFont systemFontOfSize:17];
//    [navBar setTitleTextAttributes:textAttrs1];
////    [navBar setBarTintColor:[UIColor colorWithHex:0xff021d32]];
////    navBar.translucent = NO;
//    [navBar setBackgroundImage:[UIImage imageNamed:@"nav"]forBarMetrics:UIBarMetricsDefault];
//
//}
- (void)viewDidLoad {
    [super viewDidLoad];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

    [self.navigationItem setHidesBackButton:YES];
//    self.navigationBar.translucent = NO;
    [self create];
}

 - (void)create
{
    _img = [[UIImageView alloc]initWithImage:imageNamed(@"nav")];
    [self.navigationBar insertSubview:_img atIndex:1];
//    _img.frame = self.navigationBar.bounds;
    _img.frame = CGRectMake(0, - 20, kScreenWidth, 64 );
    _img.userInteractionEnabled = YES;
    self.navigationItem.leftBarButtonItem = NULL;
    
    _button = [UIButton createButton];
    _button.frame = CGRectMake(8, 20, 40, 40);
    _button.hitTestEdgeInsets = UIEdgeInsetsMake(-10, -10, -10, -20);
    [_button setImage:[UIImage imageNamed:@"arrow_alpha"] forState:UIControlStateNormal];
    [_button addTarget:self action:@selector(selectorStr) forControlEvents:UIControlEventTouchUpInside];
    [self.img addSubview:_button];
    
    CGFloat font;
    if (IS_IPHONE_4_OR_LESS) {
        font = 14.;
    }else if (IS_IPHONE_5_OR_LESS)
    {
        font = 14.;
    }else if (IS_IPHONE_6)
    {
        font = 17.;
    }else
    {
        font = 17.;
    }
    
    _titleLab = [[UILabel alloc]initWithFrame:CGRectMake(kScreenWidth/2 - Sampux6WScale(250)/2, 20, Sampux6WScale(250), 40)];
    [self.img addSubview:_titleLab];
    _titleLab.textColor = THWhiteAlplaColor(0.8);
    //    _titleLab.backgroundColor = RandomColor;
    _titleLab.textAlignment = NSTextAlignmentCenter;
    //    _titleLab.font = THFont(12.);
    
    _rightBtn = [UIButton createButton];
    [self.img addSubview:_rightBtn];
    [_rightBtn setImage:imageNamed(@"house_white") forState:UIControlStateNormal];
    _rightBtn.frame = CGRectMake(kScreenWidth - 10 - 40, 20, 40, 40);
    [_rightBtn addTarget:self action:@selector(rightItemClick) forControlEvents:UIControlEventTouchUpInside];
    self.rightBtn.hidden = YES;

}
- (void)selectorStr
{
    self.rightBtn.hidden = YES;
    _img.image = imageNamed(@"nav");
//    _img.backgroundColor = THSystemClearColor;
    [self popViewControllerAnimated:YES];
}

- (void)setTitleStr:(NSString *)titleStr
{
    _titleStr = titleStr;
    self.titleLab.text = _titleStr;
}

- (void)rightItemClick
{
    self.rightBtn.hidden = YES;
    [self popToRootViewControllerAnimated:YES];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
}
@end
